<!DOCTYPE html>
<body>
<script src="../../resources/gc.js"></script>
<script src="../../resources/js-test.js"></script>
<script>
description("MessagePorts (and their execution contexts) should be collected by GC once close() has been called on them");

window.jsTestIsAsync = true;

function runGCAndTest() {
    asyncGC(function() {
        shouldBeTrue("iframeDocGC.wasCollected");
        finishJSTest();
    });
}

window.onmessage = function(evt) {
    iframeDocGC = internals.observeGC(document.querySelector('iframe').contentDocument);
    document.querySelector('iframe').remove();
    // The iframe is reachable via evt.source, and evt is on the
    // stack. Force a GC upon return from the event handler, so
    // that it no longer will be in scope and the iframe can
    // be GCed.
    setTimeout(runGCAndTest, 0);
}
</script>
<iframe src="resources/message-port-gc-closed-iframe.html"></iframe>
</body>
